# Copyright (c) 2018 CodBo.All rights reserved.
# Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
# http://opensource.org/licenses/MIT

import os, shutil,json

def rename():
	work_dir = './'
	for parent, dirnames, filenames in os.walk(work_dir):
		for filename in filenames:
			if filename.endswith(".atlas"):
				file_path = os.path.join(parent, filename)
				os.rename(file_path, file_path + ".txt")
				print(file_path)

def fixJson():
	work_dir = './'
	for parent, dirnames, filenames in os.walk(work_dir):
		for filename in filenames:
			if filename.endswith(".json"):
				file_path = os.path.join(parent, filename)
				json1 = open(file_path,'r',encoding='utf-8').read()
				if "bones" in json1 and not "skeleton" in json1:
					print(file_path)
					json1 = json1[0:2] + '"skeleton": { "hash": "0C6whivVQVuD/woFtbJBZAqNHq4", "spine": "3.5.03-beta", "width": 519.09, "height": 542.36, "fps": 30, "images": "" },\n' + json1[2:];
					open(file_path,'w',encoding='utf-8').write(json1)

print("--------rename...--------\n")
rename()
print("--------fix json...------\n")
fixJson()
print("--------All done.--------\n")
